namespace Vanilla.UI

import System

class Column (Box):
	def constructor (p as Box):
		super(p)
	
	def constructor (p as Box, f as bool):
		self(p)
		DrawFrame = f
	
	public UniformSizing as bool = false
	
	override MinSize as Size:
		get:
			return Size(2*Spacing, 2*Spacing) if Children == null
			w = Spacing*2
			h = Spacing
			for c in Children:
				h += c.MinSize.Height + Spacing
				w = System.Math.Max(w, c.MinSize.Width + 2*Spacing)
			return Size(w,h)
	
	override MaxSize as Size:
		get:
			if Expand:
				return Size(2*Spacing, 2*Spacing) if Children == null
				w = 10000.0
				h = Spacing
				for c in Children:
					h += c.MaxSize.Height + Spacing
					w = System.Math.Min(w, c.MaxSize.Width + 2*Spacing)
				return Size(w,h)
			else:
				return MinSize
	
	// ARRANGE
	override def Arrange ():
		min = MinSize
		max = MaxSize
		
		if UniformSizing:
			y = Spacing
			h = (Size.Height - Spacing - Spacing*Children.Length) / Children.Length
			for c in Children:
				c.Rect = Rect(Spacing, y, Size.Width-Spacing, y + h)
				y += h + Spacing
		else:
			ratio = (Size.Height - min.Height) / (max.Height - min.Height)
			ratio = 0 if double.IsNaN(ratio) or double.IsInfinity(ratio)
			y = Spacing
			for c in Children:
				h = c.MinSize.Height + ((c.MaxSize.Height-c.MinSize.Height) * ratio)
				c.Rect = Rect(Spacing, y, Size.Width-Spacing, y + h)
				y += h + Spacing
